package com.lp;

public class StockProfit {
    public static void main(String[] args) {
//        int[] price = new int[]{1,2,3,4,5,3,1,4,7,8};
        int[] price = new int[]{7,6,5,4,1,4};
        int stockMaxProfit = getStockMaxProfit(price);
        System.out.println(stockMaxProfit);
    }

    public static int getStockMaxProfit(int[] price){
        int max = 0;
        for (int i = 0; i < price.length-1; i++) {
            int buy = price[i];
            int sell = price[i+1];
            for(int j=i+2;j<price.length;j++){
                if(price[j]>sell){
                    sell = price[j];
                }
            }
            if(sell-buy > max){
                max= sell-buy;
            }
        }
        return max;
    }
}
